Skip to content

fix: drop a quadratic regex from the fake file watcher - #31

Merged
kkdev92 merged 1 commit into
mainfrom
fix/polynomial-redos-in-fake-watcher
Aug 12, 2026
Merged

fix: drop a quadratic regex from the fake file watcher#31
kkdev92 merged 1 commit into
mainfrom
fix/polynomial-redos-in-fake-watcher

Conversation

@kkdev92

@kkdev92 kkdev92 commented Aug 12, 2026

Copy link
Copy Markdown
Owner

/\/+$/ stripping trailing separators is polynomial: the engine retries the
greedy \/+ from every position before $ rejects it, so a base path of n
separators costs time in n². CodeQL flags it as js/polynomial-redos, high.

It is not a vulnerability, and this PR should not pretend otherwise

The input is pattern.baseUri.path from a RelativePattern the test author
constructed
. There is no untrusted path into a fake — reaching this needs you
to write the base URI yourself, in your own test.

What makes it worth fixing anyway:

  • src/testing/ is published code, not internal scaffolding
  • the defect is real independent of who can reach it
  • counting backwards is linear and easier to read than the regex was

Scope

One replace becomes a named helper. Same trailing separators removed, same
result for every input; the existing watcher suites cover it. The only other
+$ in src/ is base64 padding in html.ts, bounded at two characters — not
flagged, and correctly so.

Verification

quality, verify:package, and both real-host lanes (Extension Host and web).

🤖 Generated with Claude Code

`/\/+$/` stripping trailing separators is polynomial: the engine retries the
greedy `\/+` from every position before `$` rejects it, so a base path of n
separators costs time in n². CodeQL flags it as `js/polynomial-redos`, high.

**It is not a vulnerability here** and the commit should not pretend otherwise.
The input is `pattern.baseUri.path` from a `RelativePattern` the *test author*
constructed — there is no untrusted path into a fake. What makes it worth fixing
is that `src/testing/` is published code, the defect is real regardless of who
can reach it, and counting backwards is both linear and easier to read than the
regex was.

Behaviour is identical: same trailing separators removed, and the existing
watcher suites cover it.

Verified: quality, verify:package, and both real-host lanes.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@kkdev92
kkdev92 merged commit 45bee40 into main Aug 12, 2026
10 checks passed
@kkdev92
kkdev92 deleted the fix/polynomial-redos-in-fake-watcher branch August 12, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant